load("//bazel:mongo_src_rules.bzl", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "query_sbe_makeobj_spec",
    srcs = [
        "makeobj_spec.cpp",
        "size_estimator.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:sbe_values",
    ],
)

mongo_cc_library(
    name = "query_sbe",
    srcs = [
        "extended_types.cpp",
        "sbe_pattern_value_cmp.cpp",
        "sort_spec.cpp",
        "//src/mongo/db/exec/sbe/expressions:compile_ctx.cpp",
        "//src/mongo/db/exec/sbe/expressions:expression.cpp",
        "//src/mongo/db/exec/sbe/expressions:runtime_environment.cpp",
        "//src/mongo/db/exec/sbe/util:debug_print.cpp",
        "//src/mongo/db/exec/sbe/util:pcre.cpp",
        "//src/mongo/db/exec/sbe/util:spilling.cpp",
        "//src/mongo/db/exec/sbe/util:stage_results_printer.cpp",
        "//src/mongo/db/exec/sbe/vm:code_fragment.cpp",
        "//src/mongo/db/exec/sbe/vm:vm.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_arith.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_block.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_acc_finalize.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_agg.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_arith.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_array.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_bit.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_bool.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_bson.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_datetime.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_hash.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_keystring.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_makebsonobj.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_makeobj.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_object.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_predicate.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_regex.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_set.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_sortkey.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_builtin_string.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_datetime.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_instruction.cpp",
        "//src/mongo/db/exec/sbe/vm:vm_printer.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/bson/dotted_path:dotted_path_support",
        "//src/mongo/db:mongohasher",
        "//src/mongo/db:sbe_values",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/exec:str_trim_utils",
        "//src/mongo/db/exec:substr_utils",
        "//src/mongo/db/exec/sbe:query_sbe_makeobj_spec",
        "//src/mongo/db/fts:base_fts",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/query:random_utils",
        "//src/mongo/db/query:spill_util",
        "//src/mongo/db/query/compiler/logical_model/sort_pattern",
        "//src/mongo/db/query/compiler/metadata:query_metadata",
        "//src/mongo/db/query/compiler/physical_model/index_bounds",
        "//src/mongo/db/query/util:field_set",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/sorter:sorter_base",
        "//src/mongo/db/sorter:sorter_stats",
        "//src/mongo/db/storage:record_store_base",
        "//src/mongo/db/storage:spill_table",
        "//src/third_party/snappy",
    ],
)

mongo_cc_library(
    name = "query_sbe_plan_stats",
    srcs = [
        "//src/mongo/db/exec/sbe/stages:plan_stats.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:cluster_role",
        "//src/mongo/db/pipeline/spilling:spilling_stats",
        "//src/mongo/db/query/client_cursor:cursor_response_idl",
    ],
)

mongo_cc_library(
    name = "query_sbe_stages",
    srcs = [
        "//src/mongo/db/exec/sbe/stages:agg_project.cpp",
        "//src/mongo/db/exec/sbe/stages:block_hashagg.cpp",
        "//src/mongo/db/exec/sbe/stages:block_to_row.cpp",
        "//src/mongo/db/exec/sbe/stages:branch.cpp",
        "//src/mongo/db/exec/sbe/stages:bson_scan.cpp",
        "//src/mongo/db/exec/sbe/stages:co_scan.cpp",
        "//src/mongo/db/exec/sbe/stages:extract_field_paths.cpp",
        "//src/mongo/db/exec/sbe/stages:fetch.cpp",
        "//src/mongo/db/exec/sbe/stages:hash_agg.cpp",
        "//src/mongo/db/exec/sbe/stages:hash_agg_accumulator.cpp",
        "//src/mongo/db/exec/sbe/stages:hash_join.cpp",
        "//src/mongo/db/exec/sbe/stages:hash_lookup.cpp",
        "//src/mongo/db/exec/sbe/stages:hash_lookup_unwind.cpp",
        "//src/mongo/db/exec/sbe/stages:hashagg_base.cpp",
        "//src/mongo/db/exec/sbe/stages:limit_skip.cpp",
        "//src/mongo/db/exec/sbe/stages:lookup_hash_table.cpp",
        "//src/mongo/db/exec/sbe/stages:loop_join.cpp",
        "//src/mongo/db/exec/sbe/stages:makeobj.cpp",
        "//src/mongo/db/exec/sbe/stages:merge_join.cpp",
        "//src/mongo/db/exec/sbe/stages:project.cpp",
        "//src/mongo/db/exec/sbe/stages:search_cursor.cpp",
        "//src/mongo/db/exec/sbe/stages:sort.cpp",
        "//src/mongo/db/exec/sbe/stages:sort_stage_sort_impl.cpp",
        "//src/mongo/db/exec/sbe/stages:sorted_merge.cpp",
        "//src/mongo/db/exec/sbe/stages:ts_bucket_to_cell_block.cpp",
        "//src/mongo/db/exec/sbe/stages:union.cpp",
        "//src/mongo/db/exec/sbe/stages:unique.cpp",
        "//src/mongo/db/exec/sbe/stages:unwind.cpp",
        "//src/mongo/db/exec/sbe/stages:virtual_scan.cpp",
        "//src/mongo/db/exec/sbe/stages:window.cpp",
    ],
    deps = [
        ":query_sbe",
        ":query_sbe_plan_stats",
        ":query_sbe_storage",
        "//src/mongo/bson/dotted_path:dotted_path_support",
        "//src/mongo/db:sbe_values",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/exec:js_function",
        "//src/mongo/db/exec:scoped_timer",
        "//src/mongo/db/pipeline",
        "//src/mongo/db/query:plan_yield_policy",
        "//src/mongo/db/query:query_knobs",
        "//src/mongo/db/query:spill_util",
        "//src/mongo/db/query/compiler/metadata:query_metadata",
        "//src/mongo/db/query/compiler/physical_model/index_bounds",
        "//src/mongo/db/query/stage_memory_limit_knobs",
        "//src/mongo/db/shard_role/lock_manager",
        "//src/mongo/db/sorter:sorter_base",
        "//src/mongo/db/sorter:sorter_stats",
        "//src/mongo/db/storage:encryption_hooks",
        "//src/mongo/db/storage:index_entry_comparison",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/executor:task_executor_cursor",
        "//src/mongo/util/concurrency:thread_pool",
        "//src/third_party/snappy",
    ],
)

mongo_cc_library(
    name = "query_sbe_storage",
    srcs = [
        "//src/mongo/db/exec/sbe/stages:collection_helpers.cpp",
        "//src/mongo/db/exec/sbe/stages:ix_scan.cpp",
        "//src/mongo/db/exec/sbe/stages:random_scan.cpp",
        "//src/mongo/db/exec/sbe/stages:scan.cpp",
    ],
    deps = [
        ":query_sbe",
        "//src/mongo/db/exec:scoped_timer",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/index:preallocated_container_pool",
        "//src/mongo/db/query/compiler/physical_model/index_bounds",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/storage:index_entry_comparison",
    ],
)

mongo_cc_library(
    name = "sbe_plan_stage_test",
    srcs = [
        "sbe_plan_stage_test.cpp",
    ],
    deps = [
        ":query_sbe",
        ":query_sbe_stages",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/shard_role/shard_catalog:catalog_test_fixture",
        "//src/mongo/executor:network_interface_mock",
        "//src/mongo/executor:task_executor_cursor",
        "//src/mongo/executor:task_executor_interface",
        "//src/mongo/executor:thread_pool_task_executor",
        "//src/mongo/executor:thread_pool_task_executor_test_fixture",
        "//src/mongo/unittest",
    ],
)

mongo_cc_library(
    name = "sbe_unittest_base",
    srcs = [
        "sbe_unittest.cpp",
    ],
    deps = [
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/db/query:query_test_service_context",
    ],
)

mongo_cc_unit_test(
    name = "makeobj_spec_hash_test",
    srcs = [
        "makeobj_spec_hash_test.cpp",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        ":query_sbe_makeobj_spec",
        ":sbe_unittest_base",
    ],
)

mongo_cc_unit_test(
    name = "db_sbe_test",
    srcs = [
        "sbe_agg_project_test.cpp",
        "sbe_block_hashagg_test.cpp",
        "sbe_block_stages_test.cpp",
        "sbe_code_fragment_test.cpp",
        "sbe_extract_field_paths_test.cpp",
        "sbe_filter_test.cpp",
        "sbe_hash_agg_accumulator_test.cpp",
        "sbe_hash_agg_test.cpp",
        "sbe_hash_join_test.cpp",
        "sbe_hash_lookup_shared_test.cpp",
        "sbe_hash_lookup_test.cpp",
        "sbe_hash_lookup_unwind_test.cpp",
        "sbe_key_string_test.cpp",
        "sbe_limit_skip_test.cpp",
        "sbe_loop_join_test.cpp",
        "sbe_math_builtins_test.cpp",
        "sbe_merge_join_test.cpp",
        "sbe_mkobj_test.cpp",
        "sbe_numeric_convert_test.cpp",
        "sbe_pattern_value_cmp_test.cpp",
        "sbe_plan_size_test.cpp",
        "sbe_scan_test.cpp",
        "sbe_search_cursor_test.cpp",
        "sbe_sort_test.cpp",
        "sbe_sorted_merge_test.cpp",
        "sbe_test.cpp",
        "sbe_trial_run_tracker_test.cpp",
        "sbe_unique_test.cpp",
        "sbe_window_test.cpp",
        "write_value_to_stream_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_array_set_conversion_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_block_expr_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_block_top_bottom_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_bson_size_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_coerce_to_string_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_collIsMember_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_concat_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_constant_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_covariance_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_current_date_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_add_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_diff_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_expression_accepting_timezone_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_from_string_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_to_parts_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_to_string_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_date_trunc_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_derivative_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_exp_moving_avg_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_extract_sub_array_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_fail_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_fill_type_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_firstn_lastn_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_get_element_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_if_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_index_of_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_integral_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_is_array_empty_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_is_member_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_iso_date_to_parts_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_ks_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_lambda_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_linearfill_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_local_bind_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_mod_expression_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_new_array_from_range_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_object_array_conversion_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_prim_binary_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_prim_nary_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_prim_unary_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_rank_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_regex_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_removable_avg_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_removable_min_max_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_removable_minn_maxn_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_removable_push_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_removable_stddev_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_removable_sum_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_replace_one_expression_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_reverse_array_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_round_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_runtime_environment_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_set_expressions_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_shard_filter_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_to_upper_to_lower_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_topn_bottomn_expr_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_topn_bottomn_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_trigonometric_expressions_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_trunc_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_ts_second_ts_increment_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_unwind_array_builtin_test.cpp",
        "//src/mongo/db/exec/sbe/expressions:sbe_variable_test.cpp",
        "//src/mongo/db/exec/sbe/util:stage_results_printer_test.cpp",
        "//src/mongo/db/exec/sbe/values:block_test.cpp",
        "//src/mongo/db/exec/sbe/values:bsoncolumn_materializer_test.cpp",
        "//src/mongo/db/exec/sbe/values:object_walk_node_scalar_test.cpp",
        "//src/mongo/db/exec/sbe/values:row_test.cpp",
        "//src/mongo/db/exec/sbe/values:slot_printer_test.cpp",
        "//src/mongo/db/exec/sbe/values:slot_test.cpp",
        "//src/mongo/db/exec/sbe/values:ts_block_test.cpp",
        "//src/mongo/db/exec/sbe/values:value_serialization_test.cpp",
        "//src/mongo/db/exec/sbe/values:value_test.cpp",
        "//src/mongo/db/exec/sbe/vm:code_fragment_test.cpp",
    ],
    data = [
        "//src/mongo/db/test_output/exec/sbe:test_data",
    ],
    tags = ["mongo_unittest_eighth_group"],
    deps = [
        ":sbe_plan_stage_test",
        ":sbe_unittest_base",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/query/collation:collator_interface_mock",
        "//src/mongo/db/timeseries:bucket_compression",
        "//src/mongo/unittest",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_benchmark(
    name = "sbe_expression_bm",
    srcs = [
        "//src/mongo/db/exec/sbe/expressions:sbe_expression_bm.cpp",
    ],
    deps = [
        ":query_sbe_stages",
        "//src/mongo/db:query_exec",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/exec:expression_bm_fixture",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/shard_role:service_context_non_d",
    ],
)

mongo_cc_benchmark(
    name = "sbe_vm_bm",
    srcs = [
        "//src/mongo/db/exec/sbe/vm:vm_bm.cpp",
    ],
    tags = [
        "first_half_bm",
    ],
    deps = [
        ":query_sbe",
        "//src/mongo/db/query/collation:collator_icu",
        "//src/mongo/unittest",
    ],
)

mongo_cc_benchmark(
    name = "sbe_extract_field_paths_bm",
    srcs = [
        "//src/mongo/db/exec/sbe/values:extract_field_paths_bm.cpp",
    ],
    deps = [
        ":sbe_plan_stage_test",
        ":sbe_unittest_base",
        "//src/mongo/db:query_exec",
        "//src/mongo/db/exec:expression_bm_fixture",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/unittest",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_benchmark(
    name = "sbe_scan_test",
    srcs = [
        "//src/mongo/db/exec/sbe:sbe_scan_test.cpp",
    ],
    deps = [
        ":query_sbe_stages",
        ":sbe_plan_stage_test",
        ":sbe_unittest_base",
        "//src/mongo/db:query_exec",
        "//src/mongo/db/exec:expression_bm_fixture",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/unittest",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_benchmark(
    name = "sbe_ix_scan_bm",
    srcs = [
        "//src/mongo/db/exec/sbe:sbe_ix_scan_bm.cpp",
    ],
    deps = [
        ":query_sbe_stages",
        ":sbe_plan_stage_test",
        ":sbe_unittest_base",
        "//src/mongo/db:query_exec",
        "//src/mongo/db/exec:expression_bm_fixture",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/unittest",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_benchmark(
    name = "sbe_hash_lookup_bm",
    srcs = [
        "sbe_hash_lookup_shared_test.cpp",
        "//src/mongo/db/exec/sbe:sbe_hash_lookup_bm.cpp",
    ],
    private_hdrs = [
        ":sbe_block_test_helpers.h",
        ":sbe_hash_lookup_shared_test.h",
        "//src/mongo/db/query/stage_builder/sbe/tests:sbe_builder_test_fixture.h",
    ],
    deps = [
        ":sbe_plan_stage_test",
        ":sbe_unittest_base",
        "//src/mongo/unittest",
    ],
)
